import $ from 'jquery';

let goTop = () => {
    let goTop = document.createElement('div'),
        goTopBtn = document.createElement('a');
    goTop.className = 'goTop transition';
    goTopBtn.href = '#';
    goTop.appendChild(goTopBtn);
    document.body.appendChild(goTop);
    window.onscroll = () => {
        let scrollTop = document.documentElement.scrollTop;
        if (scrollTop >= 1200) {
            goTop.className = 'goTop transition show';
        } else {
            goTop.className = 'goTop transition';
        }
    };
    goTopBtn.onclick = e => {
        e.preventDefault();
        $('html, body').animate({
            'scrollTop': 0
        }, 500);
    }
}

export default goTop;